package com.yaoxun.bored;

import java.util.Properties;

import javax.validation.Validation;
import javax.validation.Validator;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.util.Config;

@Configuration
public class BeanConfig {
	
	
	/**
	 * 配置kaptcha 处理器
	 * @author Loren
	 * @createTime 2018年1月31日 下午5:42:09
	 * @return
	 */
	@Bean
	public Producer producer() {
		Properties properties = new Properties();
		Config config = new Config(properties);
		Producer producer = config.getProducerImpl();
		return producer;
	}
	
	/**
	 * 配置 HibernateValidator 为快速失败模式
	 * @author Loren
	 * @createTime 2018年1月29日 下午6:02:58
	 * @return
	 */
	@Bean
	public Validator validator() {
		Validator validator = Validation.byProvider(HibernateValidator.class)
					.configure().addProperty("hibernate.validator.fail_fast", "true")
					.buildValidatorFactory().getValidator();
		return validator;
	}
	
}
